package com.campus.commons.utils.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.enums.WriteDirectionEnum;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.alibaba.excel.write.metadata.fill.FillWrapper;
import com.campus.commons.utils.Tool;
import sun.util.calendar.Gregorian;

import java.io.File;
import java.util.*;

public class EasyExcel_X {
    /**
     *  按照模板导出，Map可以放空的key，这样取对象就不用 加前戳
     * @param templatePath 模板文件地址
     * @param outPath      文件输出路径
     * @param data        要导出的数据
     * @return
     */
    public static File writeExcel(String templatePath, String outPath, Map<String, Object> data) {
        File file = new File(outPath);
        ExcelWriter excelWriter = EasyExcel.write(file).withTemplate(templatePath).build();
        WriteSheet writeSheet = EasyExcel.writerSheet().build();
        Set<String> keys = data.keySet();
        Map<String, Object> map = new HashMap<String, Object>();
        for (String key : keys) {
            Object value = data.get(key);
            if (value instanceof List) {
                excelWriter.fill(new FillWrapper(key, (List) value), writeSheet);
            } else {
                map.put(key, value);
            }
        }
        excelWriter.fill(map, writeSheet);
        excelWriter.finish();
        return file;
    }

    public static void main(String[] args) {
        Date date = Tool.getDate("12月23日", "MM月dd日");
        new Date().getYear();
//        new Date().getCalendarDate();
        Calendar.getInstance().get(Calendar.YEAR);
        System.out.println();
    }
}
